﻿using System;
using StyleMVVM.DependencyInjection.Impl;

namespace StyleMVVM.DependencyInjection.Conditions
{
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
	public class ExportWhenConditionAttribute : Attribute, IExportConditionAttribute
	{
		private readonly string condition;
		private object value = true;

		public ExportWhenConditionAttribute(string condition)
		{
			this.condition = condition;
		}

		public ExportWhenConditionAttribute(string condition, object value)
		{
			this.condition = condition;
			this.value = value;
		}

		public IExportCondition ProvideCondition(Type exportType)
		{
			return new SimpleExportCondition((x, y, z) => Equals(y.GetConditionValue(condition), value));
		}
	}
}